package com.pai4j.pay.repository.entity;


import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
@Entity
@Table(name = "web_chat_payment_order")
public class PaymentOrderEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "order_id", nullable = false, length = 64)
    private String orderId;

    @Column(name = "trans_id", nullable = false, length = 64)
    private String transId;

    @Column(name = "business_id", nullable = false, length = 64)
    private String  businessId;

    /**
     * 接入方自定义业务事件
     */
    @Column(name = "business_action", nullable = false, length = 64)
    private String  businessAction;

    @Column(name = "status", nullable = false)
    private Integer status;

    @Column(name = "app_id", nullable = false)
    private Long appId;

    @Column(name = "event_type", nullable = false)
    private Integer eventType;

    @Column(name = "bill_type", nullable = false)
    private Integer billType;

    @Column(name = "amount", nullable = false, precision = 10, scale = 2)
    private BigDecimal amount;

    @Column(name = "source_account", nullable = false, length = 64)
    private String sourceAccount;

    @Column(name = "target_account", nullable = false, length = 64)
    private String targetAccount;

    @Column(name = "description", length = 100)
    private String description;

    /**
     * 延迟队列根据过期时间处理过期订单
     */
    @Column(name = "expire_date")
    private Date expireDate;

    @Column(name = "CREATE_DATE", updatable = false)
    private Date createDate;

    @Column(name = "UPDATE_DATE")
    private Date updateDate;

    @Version
    @Column(name = "VERSION")
    private Integer version;

    @PrePersist
    protected void onCreate() {
        if (createDate == null) {
            createDate = new Date();
        }
    }

    @PreUpdate
    protected void onUpdate() {
        updateDate = new Date();
    }
}
